package com.lyw.utils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.ArrayList;

public class indexCreate {

    public static void main(String[] args) throws IOException {
        System.out.println(new indexCreate().source("",2));
    }

    public ArrayList<fang> source(String urll,int page) throws IOException {

        String url = "https://sh.lianjia.com/zufang/";


        Document document = Jsoup.connect(url).get();
        ArrayList<fang> fangArrayList = new ArrayList<>();


        Elements lazy_load = document.getElementsByClass("content__list--item--aside");
        for (Element element : lazy_load) {
            System.out.println(element.getElementsByClass("lazyload").attr("data-src"));
        }


        Elements twoline = document.getElementsByClass("content__list--item");
        for (Element element : twoline) {
            fang fang = new fang();
            Elements elementsByClass = element.getElementsByClass("twoline");
            for (Element byClass : elementsByClass) {
                System.out.println(byClass.text());
                fang.setName(byClass.text());

                Elements elementsByClass1 = element.getElementsByClass("content__list--item--des");
                for (Element element1 : elementsByClass1) {
                    fang.setV1(element1.text());
                    System.out.println(element1.text());
                }

                Elements elementsByClass2 = element.getElementsByClass("content__list--item--bottom oneline");
                for (Element element1 : elementsByClass2) {
                    fang.setV2(element1.text());
                    System.out.println(element1.text());
                }

                Elements elementsByClass3 = element.getElementsByClass("content__list--item-price");
                for (Element element1 : elementsByClass3) {
                    fang.setV3(element1.text());
                    System.out.println(element1.text());
                }

                Elements elementsByClass4 = element.getElementsByClass("content__list--item--time oneline");
                for (Element element1 : elementsByClass4) {
                    fang.setV4("宏烨找房  " + element1.text());
                    System.out.println("宏烨找房  " + element1.text());
                }
                fangArrayList.add(fang);
                 System.out.println(fang.toString());
            }
        }
        return fangArrayList;
     }

    public ArrayList<fang> xin(String urll,int page) throws IOException {

        String url = "https://qd.fang.lianjia.com/loupan/pg2/";


        Document document = Jsoup.connect(url).get();
        ArrayList<fang> fangArrayList = new ArrayList<>();

        Elements twoline = document.getElementsByClass("resblock-list post_ulog_exposure_scroll has-results");
        for (Element element : twoline) {
            fang fang = new fang();
            Elements elementsByClass = element.getElementsByClass("name ");
            for (Element byClass : elementsByClass) {
                //System.out.println(byClass.text());
                fang.setName(byClass.text());
                Elements elementsByClass1 = element.getElementsByClass("resblock-location");
                for (Element element1 : elementsByClass1) {
                    fang.setV1(element1.text());
                    //System.out.println(element1.text());
                }

                Elements elementsByClass2 = element.getElementsByClass("resblock-room");
                for (Element element1 : elementsByClass2) {
                    fang.setV2(element1.text());
                    //System.out.println(element1.text());
                }

                Elements elementsByClass3 = element.getElementsByClass("resblock-area");
                for (Element element1 : elementsByClass3) {
                    fang.setV3(element1.text());
                    //System.out.println(element1.text());
                }

                Elements elementsByClass4 = element.getElementsByClass("resblock-tag");
                for (Element element1 : elementsByClass4) {
                    fang.setV6("宏烨找房  " + element1.text());
                    //System.out.println("宏烨找房  " + element1.text());
                }
                fangArrayList.add(fang);
                // System.out.println(fang.toString());
            }
        }
        return fangArrayList;
    }


}
